package com.xiaoxin.errorDemo.error;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.stream.Collectors;

/**
 * 模仿ErrorMvcAutoConfiguration注册BasicErrorController
 * 我们自己注册MyErrorController
 */
@Configuration
public class ErrorConfiguration {

    @Bean
    public MyErrorController basicErrorController(ErrorAttributes errorAttributes,
                                                  ObjectProvider<ErrorViewResolver> errorViewResolvers,
                                                  ServerProperties serverProperties) {
        return new MyErrorController(errorAttributes,
                serverProperties.getError(),
                errorViewResolvers.orderedStream().collect(Collectors.toList()));
    }

}
